#pragma once

#include "SffManager.h"
#include "AirManager.h"

#include <QObject>
#include <QMap>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QStandardPaths>
#include <QFileDialog>
#include <QApplication>
#include <QtDebug>
#include <QDir>
#include <QFileInfo>
#include <QTimer>

struct SpriteGroup {
    int Id;
    QMap<int, int> MapOfGroupSpriteNumToRealSpriteIdx;
    // QList<int> SpriteIdxList;
};

class Model : public QObject
{
    Q_OBJECT
public:
    explicit Model(QObject *parent = nullptr);

    QString OpenLoadSffFileDlg();
    QString OpenLoadAirFileDlg();
    void LoadSff(const QString &path);
    void LoadAir(const QString &path);
    void OpenExportFileDlg();
    void Export(const QString &outputDirPath);

    const QList<Action> &GetActionList();
    // const std::vector<Sprite> &GetAllSpriteVector();
//    QList<Sprite> GetSpriteListByGroup(const SpriteGroup &g);
    QList<Sprite> GetSpriteListByAction(const Action &a);
    QImage GetSpriteImg(const Sprite &sprite);
Q_SIGNALS:
    void LoadAirFinished();

private:
    QString getFilePathByFileDlg(const QString &title, const QString &suffix);
    QString getDirPathByFileDlg();

private:
    AirManager m_airManager;
    Sff m_sff;
    // QList<Sprite> m_spriteList;
//    QList<SpriteGroup> m_spriteGroupList;
    QMap<int, SpriteGroup> m_mapOfIdToSpriteGroup;
    QList<Action> m_actionList;
};
